package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.annotation.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumTrackListVo;
import com.atguigu.tingshu.vo.album.TrackInfoVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import com.atguigu.tingshu.vo.album.UploadTrackVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.nio.channels.MulticastChannel;
import java.util.List;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album/trackInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class TrackInfoApiController {

	@Autowired
	private TrackInfoService trackInfoService;

	/**
	 * 分页查询用户声音列表
	 * @param pageNo
	 * @param pageSize
	 * @param trackInfoQuery
	 * @return
	 */
	@PostMapping("/findUserTrackPage/{page}/{limit}")
	@GuiGuLogin
	public Result<IPage<TrackListVo>> findUserTrackPage(@PathVariable("page") Long pageNo, @PathVariable("limit") Long pageSize, @RequestBody TrackInfoQuery trackInfoQuery) {
		IPage<TrackListVo> page = trackInfoService.findUserTrackPage(pageNo,pageSize,trackInfoQuery);
		return Result.ok(page);
	}


	/**
	 * 上传声音
	 * @param file
	 * @return
	 */
	@PostMapping("/uploadTrack")
	public Result<UploadTrackVo> uploadTrack(MultipartFile file){
		UploadTrackVo uploadTrackVo = trackInfoService.uploadTrack(file);
		return Result.ok(uploadTrackVo);
	}

	/**
	 * 保存声音
	 * @param trackInfoVo
	 * @return
	 */
	@PostMapping("/saveTrackInfo")
	@GuiGuLogin
	public Result saveTrackInfo(@RequestBody TrackInfoVo trackInfoVo){
		trackInfoService.saveTrackInfo(trackInfoVo);
		return Result.ok();
	}


	@GetMapping("/getTrackInfo/{id}")
	@GuiGuLogin
	public Result<TrackInfo> getTrackInfo(@PathVariable Long id){
		TrackInfo trackInfo = trackInfoService.getById(id);
		return Result.ok(trackInfo);
	}

	/**
	 * 修改声音
	 * @param id
	 * @param trackInfoVo
	 * @return
	 */
	@PutMapping("/updateTrackInfo/{id}")
	public Result updateTrackInfo(@PathVariable Long id,@RequestBody TrackInfoVo trackInfoVo){
		trackInfoService.updateTrackInfo(id,trackInfoVo);
		return Result.ok();
	}


	@DeleteMapping("/removeTrackInfo/{id}")
	public Result removeTrackInfo(@PathVariable Long id){
		trackInfoService.removeTrackInfo(id);
		return Result.ok();
	}


	///api/album/trackInfo/findAlbumTrackPage/{albumId}/{page}/{limit}
	@GuiGuLogin
	@GetMapping("/findAlbumTrackPage/{albumId}/{page}/{limit}")
	public Result<IPage<AlbumTrackListVo>> findAlbumTrackPage(@PathVariable Long albumId, @PathVariable("page") Integer pageNo, @PathVariable("limit") Integer pageSize){
		IPage<AlbumTrackListVo> page = trackInfoService.findAlbumTrackPage(albumId,pageNo,pageSize);
		return  Result.ok(page);
	}
}

